<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* @framework : Codeigniter Framework
*
* @author: fatangel26
*
*/

	class Cms_Model extends CI_Model
	{
		public function __construct()
		{
			parent::__construct();

            $this->load->database();
		}

        /*Basic Method*/

        public function select($data = array())
        {
            if(empty($data))
            {
                $query = $this->db->get('tbl_cms');

                if($query->num_rows()>0)
                    return $query->result_object();
            }

            if(isset($data['id']))
                $query = $this->db->get_where('tbl_cms', $data);
            if($query->num_rows()>0)
                return $query->row();

            return FALSE;
        }

        public function delete()
        {

        }

        public function create()
        {

        }

        public function edit($cms_id, $data = array())
        {
            $strSQL = "UPDATE tbl_cms SET content = ?, update_time = NOW() WHERE id = ?";

            $query = $this->db->query($strSQL, array($data['content'], $cms_id ));

            if($query)
                return TRUE;
            return FALSE;
        }

        /************************************SUPPORT******************************************/
        public function select_support($data = array())
        {
            if(empty($data))
            {
                $query = $this->db->get('tbl_support');

                if($query->num_rows()>0)
                    return $query->result_object();
            }
            else
            {
                $query = $this->db->get_where('tbl_support',$data);

                if($query->num_rows()>0)
                    return $query->row();
            }

            return FALSE;
        }

        public function delete_support($data = array())
        {
            $query = $this->db->delete('tbl_support',$data);

            if($this->db->affected_rows()>0)
                return TRUE;
            return FALSE;
        }

        public function edit_support($support_id, $data = array())
        {
            if(isset($data['support_name']))
                $this->db->set('support_name', $data['support_name']);
            if(isset($data['support_yh']))
                $this->db->set('support_yh', $data['support_yh']);
            if(isset($data['support_facebook']))
                $this->db->set('support_facebook', $data['support_facebook']);
            if(isset($data['support_mail']))
                $this->db->set('support_mail', $data['support_mail']);
            if(isset($data['support_status']))
                $this->db->set('support_status', $data['support_status']);
            if(isset($data['support_fone']))
                $this->db->set('support_fone', $data['support_fone']);

            $this->db->where('support_id', $support_id);

            if($this->db->update('tbl_support'))
                return TRUE;
            return FALSE;
        }

        public function create_support($data = array())
        {
            $query = $this->db->insert('tbl_support', $data);

            if($this->db->affected_rows()>0)
                return TRUE;
            return FALSE;
        }

        /************************************LINK******************************************/
        public function select_link($data = array())
        {
            if(empty($data))
            {
                $query = $this->db->order_by('link_id','desc')
                                  ->get('tbl_link');

                if($query->num_rows()>0)
                    return $query->result_object();
            }
            else
            {
                $query = $this->db->get_where('tbl_link', $data);

                if($query->num_rows()>0)
                    return $query->row();
            }

            return FALSE;
        }

        public function delete_link($data = array())
        {
            $query = $this->db->delete('tbl_link',$data);

            if($this->db->affected_rows()>0)
                return TRUE;
            return FALSE;
        }

        public function edit_link($link_id, $data = array())
        {
            if(isset($data['link_company']))
                $this->db->set('link_company', $data['link_company']);
            if(isset($data['link']))
                $this->db->set('link', $data['link']);
            if(isset($data['link_open']))
                $this->db->set('link_open', $data['link_open']);
            if(isset($data['link_status']))
                $this->db->set('link_status', $data['link_status']);
            if(isset($data['link_image']))
                $this->db->set('link_image', $data['link_image']);
            if(isset($data['link_image_thumb']))
                $this->db->set('link_image_thumb', $data['link_image_thumb']);

            $this->db->where('link_id', $link_id);

            if($this->db->update('tbl_link'))
                return TRUE;
            return FALSE;
        }

        public function create_link($data = array())
        {
            $query = $this->db->insert('tbl_link', $data);

            if($this->db->affected_rows() > 0)
                return TRUE;
            return FALSE;
        }

	}

/* End of file Pages_model.php */
/* Location: ./models/backend/cms_model.php */